package com.ruoyi.project.product.attr.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.product.attr.domain.ProductAttrKey;
import com.ruoyi.project.product.attr.service.IProductAttrKeyService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 属性模板Controller
 * 
 * @author wyh
 * @date 2024-08-05
 */
@RestController
@RequestMapping("/product/attr")
public class ProductAttrKeyController extends BaseController
{
    @Autowired
    private IProductAttrKeyService productAttrKeyService;

    /**
     * 查询属性模板列表
     */
    @PreAuthorize("@ss.hasPermi('product:attr:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProductAttrKey productAttrKey)
    {
        startPage();
        List<ProductAttrKey> list = productAttrKeyService.selectProductAttrKeyList(productAttrKey);
        return getDataTable(list);
    }

    /**
     * 导出属性模板列表
     */
    @PreAuthorize("@ss.hasPermi('product:attr:export')")
    @Log(title = "属性模板", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProductAttrKey productAttrKey)
    {
        List<ProductAttrKey> list = productAttrKeyService.selectProductAttrKeyList(productAttrKey);
        ExcelUtil<ProductAttrKey> util = new ExcelUtil<ProductAttrKey>(ProductAttrKey.class);
        util.exportExcel(response, list, "属性模板数据");
    }

    /**
     * 获取属性模板详细信息
     */
    @PreAuthorize("@ss.hasPermi('product:attr:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(productAttrKeyService.selectProductAttrKeyById(id));
    }

    /**
     * 新增属性模板
     */
    @PreAuthorize("@ss.hasPermi('product:attr:add')")
    @Log(title = "属性模板", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProductAttrKey productAttrKey)
    {
        return toAjax(productAttrKeyService.insertProductAttrKey(productAttrKey));
    }

    /**
     * 修改属性模板
     */
    @PreAuthorize("@ss.hasPermi('product:attr:edit')")
    @Log(title = "属性模板", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProductAttrKey productAttrKey)
    {


        return toAjax(productAttrKeyService.updateProductAttrKey(productAttrKey));
    }

    /**
     * 删除属性模板
     */
    @PreAuthorize("@ss.hasPermi('product:attr:remove')")
    @Log(title = "属性模板", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(productAttrKeyService.deleteProductAttrKeyByIds(ids));
    }
}
